package cn.wangliang181230.boot.web.propertysourceloader;

import org.springframework.boot.env.PropertySourceLoader;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MyPropertySourceLoader implements PropertySourceLoader {

	@Override
	public String[] getFileExtensions() {
		return new String[]{"config"};
	}

	@Override
	public List<PropertySource<?>> load(String name, Resource resource) throws IOException {
		List<PropertySource<?>> list = new ArrayList<>();


		//region 这里，我就简单放了些代码，实际上，需要将resource的文件给读取并解析，生成一个配置源放入列表的。解析代码我就不加了。

		HashMap<String, Object> map = new HashMap<>();
		map.put("name", name);

		MapPropertySource mapPropertySource = new MapPropertySource(name, map);
		list.add(mapPropertySource);

		//endregion


		return list;
	}
}
